#include "SelectTexture.hpp"
#include "gl.hpp"
#include "glu.hpp"

SelectTexture::SelectTexture()
{
   glGenTextures(1, &mTexId);
   glBindTexture(GL_TEXTURE_2D, mTexId);
   glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
   // when texture area is small, bilinear filter the closest mipmap
   glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
      GL_LINEAR_MIPMAP_NEAREST );
   // when texture area is large, bilinear filter the original
   //glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
   glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   

   // the texture wraps over at the edges (repeat)
   glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
   glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

   //unsigned char data[4*4] = { 0,0,0,0, 255,255,255,255, 255,255,255,255, 0,0,0,0 };
   unsigned char data[4*4] = { 255,255,0,255, 0,255,255,255, 0,255,255,255, 255,255,0,255 };
   gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, data );

}
SelectTexture& SelectTexture::GetInstance()
{
   static SelectTexture i;
   return i;
}
//static 
void SelectTexture::Bind()
{
   glEnable( GL_TEXTURE_2D );
   glBindTexture( GL_TEXTURE_2D, GetInstance().mTexId);
}
//static 
void SelectTexture::Unbind()
{
   glBindTexture( GL_TEXTURE_2D, 0);
   glDisable( GL_TEXTURE_2D );
}
